package com.gosophia.conference.action.confPrepare;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.conferenceManagement.common.dto.DocumentDTO;
import com.gosophia.conferenceManagement.confPreparation.dto.ParticipatingNameListDTO;
import com.gosophia.conferenceManagement.confPreparation.ws.ConfPreparationWebService;
import com.gosophia.oa.action.JudgeCurrentUndertaker;
/**
 * 获取会议签到表Action
 * @author wangxinbing
 * @since  2011-3-26
 *  Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@Component("GetConferenceSignTable")
@Scope("prototype")
public class GetConferenceSignTable extends BaseSupportAction {
	@Autowired
	private ConfPreparationWebService confPreparationWebService;
	@Autowired
	private JudgeCurrentUndertaker judgeCurrentUndertaker;
	private Long jobId;
	
	private String userNames = "";
	
    private String orgNames =  "";
    
    private String positionNames = "";
	@Override
	public String _execute() throws Exception {
		//判断是否匹配,如果不匹配转到异常页面
        judgeCurrentUndertaker.judgeOperationAuthority(jobId);
		List<String> users = new ArrayList<String>();
		
	    List<String> orgs = new ArrayList<String>();
	    
	    List<String> positions = new ArrayList<String>();
		List<ParticipatingNameListDTO> partic = confPreparationWebService.findParticipatingNameListsByJobId(jobId);
		for(ParticipatingNameListDTO p:partic){
			if(p.getUserName()!=null){
				users.add(p.getUserName());
			}else{
				users.add("");
			}
			if(p.getOrgName()!=null){
				orgs.add(p.getOrgName());
			}else{
				orgs.add("");
			}
			if(p.getPositionName()!=null){
				positions.add(p.getPositionName());
			}else{
				positions.add("");
			}
			
		}
		userNames = JSONArray.fromObject(users).toString().replace("\"", "\\\"");
		orgNames = JSONArray.fromObject(orgs).toString().replace("\"", "\\\"");
		positionNames = JSONArray.fromObject(positions).toString().replace("\"", "\\\"");
		return SUCCESS;
	}

	public Long getJobId() {
		return jobId;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public String getUserNames() {
		return userNames;
	}

	public void setUserNames(String userNames) {
		this.userNames = userNames;
	}

	public String getOrgNames() {
		return orgNames;
	}

	public void setOrgNames(String orgNames) {
		this.orgNames = orgNames;
	}

	public String getPositionNames() {
		return positionNames;
	}

	public void setPositionNames(String positionNames) {
		this.positionNames = positionNames;
	}

   
}
